<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>角色添加页面</title>
<link rel="stylesheet" href="layui/css/layui.css" media="all">
<style>
.layui-btn:not(.layui-btn-lg ):not(.layui-btn-sm):not(.layui-btn-xs) {
	height: 34px;
	line-height: 34px;
	padding: 0 8px;
}
</style>
</head>
<body>
	<form class="layui-form" action="">
	<div class="layui-form-item" style="margin-top: 20px;" onsubmit="false">
		<div class="layui-form-item">
			<label class="layui-form-label"><span style="color: red;">* </span>角色名称:</label>
			<div class="layui-input-inline" style="width: 350px;">
				<input type="text" id="rolename" name="rolename" required=""
			 lay-reqtext="" placeholder="请输入角色名称"
					autocomplete="off" class="layui-input">
			</div>
		</div>
		
		<div class="layui-btn-container" style="text-align: center;">
			<button class="layui-btn" lay-filter="RolesBtu" lay-submit="">
				添加</button>
		</div>
		</div>
	</form>
	<script type="text/javascript" src="layui/layui.js"></script>
	<script src="js/Global.js" type="text/javascript" charset="utf-8"></script>
	<script>
		//加载了layui的form模块
		layui.use([ 'form' ], function() {
			var form = layui.form;
			var $ = layui.jquery; //引入jquery
			//监听提交
			form.on('submit(RolesBtu)', function(data) {
				var d = data.field; //表单中的数据，定义一个对象来接收
				d.method = "add";
				//通过ajax向数据库提交数据了
				console.log(d); //提交之前的一个数据验证、通过打印的方式先手动的去判断一下这个数据
				var url = globalData.server+'public/addRoles';
				$.post(url, d,  function(data) {
					if(data.count > 0) {
						layer.msg("添加成功", {
							icon: 1,
							time: 3000
						});
						//假设这是iframe页
					var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
						parent.layer.close(index); //再执行关闭  
					} else if(data.count == -1){
						layer.msg("添加失败,角色名称不能重复！！！", {
							icon: 2,
							time: 3000
						})
					}
				}, "json");
				return false;
			});
		});

	</script>
</body>
</html>